package com.example.kotlinstudy.控制流程

fun main() {
    //When表达式
    val x = 1;
    when (x) {
        1 -> print("x == 1")
        2 -> print("x == 2")
        3, 4 -> print("1 or 2")
        else -> print("x is neither 1 nor 2")
    }

    //检测一个值在或者不在一个区间或者集合中
    val validNumbers = listOf(1, 2, 3)
    when (x) {
        in 1..10 -> print("x is in the range")
        in validNumbers -> print("x is valid")
        !in 10..20 -> print("x is outside the range")
        else -> print("none of the above")
    }
    fun hasPrefix(x: Any) = when (x) {
        is String -> x.startsWith("prefix")
        else -> false
    }
//fun Request.getBody() =
//    when (val response = executeRequest()) {
//        is Success -> response.body
//        is HttpError -> throw HttpException(response.status)
//    }
    //
}